package com.smartjobs.action;

import java.util.Map;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.smartjobs.bean.CompanyBean;
import com.smartjobs.bean.JobPostingBean;
import com.smartjobs.model.EditCompanyProfileModel;

@SuppressWarnings("serial")
public class EditCompanyProfileAction extends ActionSupport {

	String companyName;
	String emailID;
	String phoneNumber;
	String jobCode;
	String jobDescription;
	String qualification;
	int skillID;
	String location;
	JobPostingBean jobPosting;

	public JobPostingBean getJobPosting() {
		return jobPosting;
	}

	public void setJobPosting(JobPostingBean jobPosting) {
		this.jobPosting = jobPosting;
	}

	public String getJobCode() {
		return jobCode;
	}

	public void setJobCode(String jobCode) {
		this.jobCode = jobCode;
	}

	public String getJobDescription() {
		return jobDescription;
	}

	public void setJobDescription(String jobDescription) {
		this.jobDescription = jobDescription;
	}

	public String getQualification() {
		return qualification;
	}

	public void setQualification(String qualification) {
		this.qualification = qualification;
	}

	public int getSkillID() {
		return skillID;
	}

	public void setSkillID(int skillID) {
		this.skillID = skillID;
	}

	public String getLocation() {
		return location;
	}

	public void setLocation(String location) {
		this.location = location;
	}

	public String getCompanyName() {
		return companyName;
	}

	public void setCompanyName(String companyName) {
		this.companyName = companyName;
	}

	public String getEmailID() {
		return emailID;
	}

	public void setEmailID(String emailID) {
		this.emailID = emailID;
	}

	public String getPhoneNumber() {
		return phoneNumber;
	}

	public void setPhoneNumber(String phoneNumber) {
		this.phoneNumber = phoneNumber;
	}

	@SuppressWarnings({ "rawtypes", "unchecked" })
	public String UpdateProfile() {
		Map session = ActionContext.getContext().getSession();
		session.put("tabID", "profile");
		CompanyBean company = new CompanyBean();
		company.setCompanyID((int) session.get("companyID"));
		company.setCompanyName(companyName);
		company.setEmailID(emailID);
		company.setPhoneNumber(phoneNumber);
		EditCompanyProfileModel.UpdateProfile(company);
		return SUCCESS;

	}

	@SuppressWarnings({ "rawtypes", "unchecked" })
	public String InsertJobPosting() {
		Map session = ActionContext.getContext().getSession();
		session.put("tabID", "jobPostings");
		jobPosting = new JobPostingBean();
		jobPosting.setCompanyId((int) session.get("companyID"));
		jobPosting.setJobCode(jobCode);
		jobPosting.setJobDesc(jobDescription);
		jobPosting.setLocation(location);
		jobPosting.setQualification(qualification);
		if (EditCompanyProfileModel.FindJobID(jobCode,
				(int) session.get("companyID")) == 0) {
			EditCompanyProfileModel.InsertJobPosting(jobPosting);
			EditCompanyProfileModel.InsertJobPostingSkills(
					EditCompanyProfileModel.FindJobID(jobCode,
							(int) session.get("companyID")), skillID);
			session.put("jobPostingExists", 0);
		} else
			session.put("jobPostingExists", 1);

		return SUCCESS;

	}
}
